//
//  AddjiaoyuController.m
//  Ten
//
//  Created by anfuer on 2018/11/1.
//  Copyright © 2018年 xg韦. All rights reserved.
//

#import "AddjiaoyuController.h"
#import "HooDatePicker.h"
#import "PickerToolView.h"
@interface AddjiaoyuController ()<HooDatePickerDelegate>
@property (weak, nonatomic) IBOutlet UITextField *tsf1;
@property (weak, nonatomic) IBOutlet UITextField *tsf2;
@property (weak, nonatomic) IBOutlet UIButton *btn1o;
@property (weak, nonatomic) IBOutlet UIButton *btn2o;
@property (nonatomic, strong) HooDatePicker *datePicker;
@end

@implementation AddjiaoyuController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.datePicker = [[HooDatePicker alloc] initWithSuperView:self.view];
    self.datePicker.delegate = self;
    self.datePicker.datePickerMode = HooDatePickerModeDate;
    NSDateFormatter *dateFormatter = [NSDate shareDateFormatter];
    [dateFormatter setDateFormat:kDateFormatYYYYMMDD];
    NSDate *maxDate = [NSDate date];
    NSDate *minDate = [dateFormatter dateFromString:@"1960-01-01"];
    [self.datePicker setDate:[NSDate date] animated:YES];
    self.datePicker.minimumDate = minDate;
    self.datePicker.maximumDate = maxDate;
    // Do any additional setup after loading the view.
}
- (IBAction)SaveBtna:(UIButton *)sender {
    
    if ([FuncPublic TextFieldisError:_tsf1]||[FuncPublic TextFieldisError:_tsf2]) {
        
        if ([[_btn1o currentTitle]containsString:@"请选择"]||[[_btn2o currentTitle]containsString:@"请选择"]) {
            [WSProgressHUD showImage:nil status:@"请完善相关数据,再提交"];
            return;
        }
        //        resume_id（简历id）
        //        id（可选，工作经历 的id，不传为新增，传则为编辑）
        NSMutableDictionary*mdic=[NSMutableDictionary dictionary];
        [mdic setObject:_tsf1.text forKey:@"school_name"];
        [mdic setObject:_tsf2.text forKey:@"specialty_name"];
        [mdic setObject:[_btn1o currentTitle] forKey:@"graduate_time"];
        [mdic setObject:[_btn2o currentTitle] forKey:@"education"];
        [mdic setObject:_resume_id forKey:@"resume_id"];
        
        [FuncPublic getData:self parameters:mdic RequestUrl:edit_educationals success:^(NSDictionary *acountInfo) {
            [WSProgressHUD showImage:nil status:acountInfo[@"msg"]];
            
        }];
    }
    
    
    
}

- (IBAction)back:(UIButton *)sender {
    UIViewController *viewCtl = self.navigationController.viewControllers[1];
    [self.navigationController popToViewController:viewCtl animated:YES];
    
}
- (IBAction)ChanggeBtna:(UIButton *)sender {
    [_tsf1 resignFirstResponder];
    [_tsf2 resignFirstResponder];
    
    if (sender.tag==2) {
         [self.datePicker show];
    }else
    {
        
        NSArray *data = @[@"其他",@"初中",@"高中",@"中专",@"大专",@"本科",@"硕士",@"博士"];
        PickerToolView *picker = [[PickerToolView alloc]init];
        picker.dataSource = data;
        picker.didSelectItem = ^(NSInteger idx){
            
            [sender setTitle:data[idx] forState:UIControlStateNormal];
            
        };
        [picker showWithAnimation:YES];
        
    }
    
}

- (void)datePicker:(HooDatePicker *)datePicker didSelectedDate:(NSDate*)date {
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //    [dateFormatter setLocale:[NSLocale currentLocale]];
    [dateFormatter setDateFormat:@"yyyy"];
    NSString *value = [dateFormatter stringFromDate:date];
 
    [_btn1o setTitle:value forState:UIControlStateNormal];
   
}




@end
